package com.naiterui.ehp.bs.emr.vo.health;

import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bs.emr.exception.ExceptionCodes;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

/**
 * @Description 饮酒史
 * @Author gongbaoqiang
 * @Date 2020/6/2 2:30 PM
 */
@Data
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("饮酒史")
public class DrinkingVO implements Serializable {
    private static final long serialVersionUID = 5647273778033694457L;

    /**
     * 外伤史
     */
    @ApiModelProperty("选项值")
    private String value;

    /**
     * 饮酒史详情
     */
    @ApiModelProperty("饮酒史详情")
    private DrinkingDetailVO detail;


    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class DrinkingDetailVO implements Serializable{

        private static final long serialVersionUID = -663031673002709181L;
        /**
         * 饮酒时间
         */
        @ApiModelProperty("饮酒时间")
        private String  duration;

        @ApiModelProperty("饮酒时间单位")
        private String durationUnit;

        /**
         * 每天数量
         */
        @ApiModelProperty("每天数量")
        private String dayCount;

        /**
         * 每天数量单位
         */
        @ApiModelProperty("每天数量单位")
        private String dayUnit;

        public void validate() throws BusinessException {
            if(StringUtils.isBlank(duration) || StringUtils.isBlank(durationUnit) || StringUtils.isBlank(dayCount) || StringUtils.isBlank(dayUnit)){
                throw new BusinessException(ExceptionCodes.PATIENT_HEALTH_RECORD_DRINKING);
            }
        }
    }

    public void validate() throws BusinessException{
        if(StringUtils.isBlank(value)){
            throw new BusinessException(ExceptionCodes.PATIENT_HEALTH_RECORD_DRINKING);
        }
        if("有".equals(value)){
            detail.validate();
        }
    }
}
